#ifndef MODBUS_TCP_MASTER_H
#define MODBUS_TCP_MASTER_H

#include <QMainWindow>
#include <QMainWindow>
#include <QModbusRtuSerialMaster>
#include <QModbusTcpClient>
#include <QSerialPort>

namespace Ui {
class modbus_tcp_master;
}

class modbus_tcp_master : public QMainWindow
{
    Q_OBJECT

public:
    modbus_tcp_master(QWidget *parent = nullptr);
    ~modbus_tcp_master();

private slots:
    void on_connectButton_clicked();
    void on_sendButton_clicked();
    void onReadReady();
    void handleError(QModbusDevice::Error error);
    void handleConnection(QModbusDevice::State state);

private:
    Ui::modbus_tcp_master *ui;
    QModbusTcpClient *modbusDevice = nullptr;
    void setupModbusMaster();
    void updateUiState(bool connected);

    bool isValidIp(const QString &ipString);
};

#endif // MODBUS_TCP_MASTER_H